#include "ring.hpp"

void* Produce(void* argv)
{
  RingQueue<int> *q = (RingQueue<int>*) argv;

  while(true){
    int data = rand() % 100 + 1;
    q->Push(data);
    printf("#######################\n");
    printf("生产者生成：%d\n", data);
    sleep(1);
  }

}

void* Consume(void* argv)
{
  RingQueue<int> *q = (RingQueue<int>*) argv;

  while(true){
    int data = -1;
    q->Pop(data);
    printf("#######################\n");
    printf("消费者消费：%d\n", data);
    sleep(1);
  }
}

int main()
{
  srand((unsigned long)time(nullptr));
  RingQueue<int> *q = new RingQueue<int>();
  pthread_t con;
  pthread_t pro;
  
  pthread_create(&con, nullptr, Consume, (void*)q);
  pthread_create(&pro, nullptr, Produce, (void*)q);

  pthread_join(con, nullptr);
  pthread_join(pro, nullptr);
  return 0;
}
